package commandPattern;

import composite.ObjectItem;

public class Move implements Command {
	private ObjectItem objectItem;
	public ObjectItem getObjectItem() { return objectItem; }
	public void setObjectItem(ObjectItem objectItem) { this.objectItem = objectItem; }

	int oldPosX, oldPosY;
	public void setOldPosX(int oldPosX) { this.oldPosX = oldPosX; }
	public void setOldPosY(int oldPosY) { this.oldPosY = oldPosY; }
	
	int newPosX, newPosY;
	
	public void execute() {
		newPosX = objectItem.getPosX();
		newPosY = objectItem.getPosY();
		objectItem.moveObject(newPosX, newPosY);
	}

	public void redo() {
		objectItem.moveObject(newPosX, newPosY);
	}

	public void undo() {
		objectItem.moveObject(oldPosX, oldPosY);
	}
	
	/** Return a clone of command in state before execution */
	public Move clone(){
		Move commandClone = new Move();
		commandClone.setObjectItem(objectItem);
		commandClone.setOldPosX(oldPosX);
		commandClone.setOldPosY(oldPosY);
		return commandClone;
	}
}
